package example.org;

import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class ShareVia extends Activity implements OnClickListener {
	private Button mButtonUpload;
	private String lemparan;
	private Uri imageFileUri;
	private ImageView chosenImageView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sharevia);
		mButtonUpload = (Button) findViewById(R.id.button1);
		mButtonUpload.setOnClickListener(this);

		chosenImageView = (ImageView) findViewById(R.id.imageView1);
		Bundle extra = getIntent().getExtras();
		if (extra != null) {
			lemparan = extra.getString("gambar");
		}

		try {
			imageFileUri = Uri.parse(lemparan);
			BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
			bmpFactoryOptions.inJustDecodeBounds = true;
			Bitmap bmp = BitmapFactory.decodeStream(getContentResolver()
					.openInputStream(imageFileUri), null, bmpFactoryOptions);
			bmpFactoryOptions.inSampleSize = 2;
			bmpFactoryOptions.inJustDecodeBounds = false;
			bmp = BitmapFactory.decodeStream(getContentResolver()
					.openInputStream(imageFileUri), null, bmpFactoryOptions);
			chosenImageView.setImageBitmap(bmp);
		} catch (FileNotFoundException e) {
			Log.v("ERROR", e.toString());
		}
	}

	@Override
	public void onClick(View v) {
		// boolean share = false;
		Intent sharingIntent = new Intent(Intent.ACTION_SEND);
		Uri screenshotUri = Uri.parse(lemparan);

		sharingIntent.setType("image/png");
		sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
		startActivity(Intent.createChooser(sharingIntent, "Share image using"));
	}
}